﻿<Window x:Class="LockCrypt.WinPasswordGenerator"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:loc="clr-namespace:LockCrypt"
    xmlns:lex="http://schemas.root-project.org/xaml/presentation"
    xmlns:l49ui="clr-namespace:Lime49.UI;assembly=Lime49"
    xmlns:props="clr-namespace:LockCrypt.Properties"
    xmlns:l49="clr-namespace:Lime49;assembly=Lime49"
    Title="{lex:LocText LockCrypt.Core:Strings:PasswordGenerator}" Style="{StaticResource {x:Type Window}}" Icon="/LockCrypt;component/Resources/LockCrypt.ico"
    MinHeight="250" MinWidth="100" Width="450" SizeToContent="Height"
    WindowStartupLocation="CenterOwner" x:Name="root" FocusManager.FocusedElement="{Binding ElementName=txtLength}"
    Loaded="Window_Loaded" Closing="Window_Closing"
    l49:WindowService.EscapeClosesWindow="True">
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Copy" Executed="CopyToClip" CanExecute="IsItemSelected" />
        <CommandBinding Command="ApplicationCommands.Help" Executed="ShowHelp" />
        <CommandBinding Command="ApplicationCommands.New" Executed="GeneratePassword" />
        <CommandBinding Command="ApplicationCommands.Open" Executed="SelectPassword" CanExecute="IsItemSelected" />
        <CommandBinding Command="ApplicationCommands.Save" Executed="SavePasswords" />
        <CommandBinding Command="EditingCommands.Delete" Executed="ClearPasswords" />
    </Window.CommandBindings>
    <Window.Resources>
        <props:Settings x:Key="settings" />
        <BooleanToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
        <Image x:Key="copy_16" Source="pack://application:,,,/Resources/Images/copy_16.png" />
        <BitmapImage x:Key="help_16" UriSource="pack://application:,,,/Resources/Images/question_16.png" x:Shared="true" />
    </Window.Resources>
    <Grid Margin="6" Grid.IsSharedSizeScope="True" DataContext="{StaticResource settings}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="180"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <GroupBox Grid.Row="0" Header="{lex:LocText LockCrypt.Core:Strings:PossibleCharacters}">
            <Grid MaxWidth="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="2*" />
                </Grid.ColumnDefinitions>
                
                <CheckBox Grid.Row="0" Grid.Column="0" x:Name="chkUppercase" IsChecked="{Binding Default.PWUppercase,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock Text="{lex:LocText LockCrypt.Core:Strings:UppercaseCharactersFmt,FormatSegment1=A-Z}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>
                <CheckBox Grid.Row="1" Grid.Column="0" x:Name="chkLowercase" IsChecked="{Binding Default.PWLowerCase,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock Text="{lex:LocText LockCrypt.Core:Strings:LowercaseCharactersFmt,FormatSegment1=a-z}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="0" x:Name="chkExtendedAscii" IsChecked="{Binding Default.PWExtended,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock Text="{lex:LocText LockCrypt.Core:Strings:ExtendedAsciiCharacters}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>
                
                <CheckBox Grid.Row="0" Grid.Column="1" x:Name="chkDigits" IsChecked="{Binding Default.PWDigits,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock Text="{lex:LocText LockCrypt.Core:Strings:DigitsFmt,FormatSegment1=0-9}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>
                <CheckBox Grid.Row="1" Grid.Column="1" x:Name="chkBrackets" IsChecked="{Binding Default.PWBrackets,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock x:Name="lblBrackets" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>
                <CheckBox Grid.Row="2" Grid.Column="1" x:Name="chkSpecialCharacters" IsChecked="{Binding Default.PWSpecial,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Checked="specification_Changed" Unchecked="specification_Changed">
                    <TextBlock x:Name="lblSpecialCharacters" TextWrapping="Wrap" TextTrimming="CharacterEllipsis"/>
                </CheckBox>

                <Label Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Content="{lex:LocText LockCrypt.Core:Strings:TheseCharacters}"/>
                <TextBox Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" x:Name="txtExtraCharacters" TextChanged="specification_Changed" />
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="1" Header="{lex:LocText LockCrypt.Core:Strings:Options}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <CheckBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" x:Name="chkSpecificFormat" Content="{lex:LocText LockCrypt.Core:Strings:UseASpecificFormat}"
                          ToolTip="{lex:LocText LockCrypt.Core:Strings:SpecialFormatTooltip}"/>
                <Label Grid.Row="1" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Format}"/>
                <TextBox Grid.Row="1" Grid.Column="1" x:Name="txtFormat" TabIndex="1" IsEnabled="{Binding IsChecked,ElementName=chkSpecificFormat,Mode=OneWay}"
                         Text="{Binding Default.PWFormat,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
                <l49ui:ImageButton Grid.Row="1" Grid.Column="2" MinWidth="18" Command="ApplicationCommands.Help" CommandParameter="format" Image="{StaticResource help_16}" ShowText="False" 
                                 Text="{lex:LocText LockCrypt.Core:Strings:Help}" ToolTip="{lex:LocText LockCrypt.Core:Strings:WhatsThis}" Margin="2" />
                
                <Label Grid.Row="2" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:PasswordsToGenerate}"/>
                <l49ui:NumericUpDown Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" x:Name="txtNumberOfPasswords" Value="1" Minimum="1" DecimalPlaces="0" Change="1" Width="60" HorizontalAlignment="Left" />
                
                <Label Grid.Row="3" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:Length}"/>
                <l49ui:NumericUpDown Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" x:Name="txtLength" Value="{Binding Default.PWLength,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Minimum="1" DecimalPlaces="0" Change="1" Width="60" HorizontalAlignment="Left" ValueChanged="length_Changed" />
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="2" Header="{lex:LocText LockCrypt.Core:Strings:Analysis}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="labels" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                
                <Label Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:EstimatedGeneratedEntropy}"/>
                <loc:PasswordAnalyser Grid.Column="1" x:Name="analyserPredicted" />
                <l49ui:ImageButton Grid.Column="2" MinWidth="18" Command="ApplicationCommands.Help" CommandParameter="entropy" Image="{StaticResource help_16}" ShowText="False" 
                                 Text="{lex:LocText LockCrypt.Core:Strings:Help}" ToolTip="{lex:LocText LockCrypt.Core:Strings:WhatsThis}" Margin="2" />
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="3" Header="{lex:LocText LockCrypt.Core:Strings:GeneratedPasswords}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="labels" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                
                <Label Grid.Row="0" Grid.Column="0" Content="{lex:LocText LockCrypt.Core:Strings:EntropyOfSelected}"/>
                <loc:PasswordAnalyser Grid.Row="0" Grid.Column="1" x:Name="analyserSelected" Margin="2,2,0,4" Password="{Binding SelectedValue,ElementName=lstPasswords,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
                <ListBox Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" x:Name="lstPasswords" ItemsSource="{Binding GeneratedPasswords,ElementName=root,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                         MinHeight="20" SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="False">
                    <ListBox.Resources>
                        <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                            <EventSetter Event="MouseDoubleClick" Handler="lst_MouseDoubleClick"/>
                        </Style>
                    </ListBox.Resources>
                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:Copy}" Command="ApplicationCommands.Copy" Icon="{StaticResource copy_16}" />
                            <MenuItem Header="{lex:LocText LockCrypt.Core:Strings:SelectPassword}" Command="ApplicationCommands.Open" Visibility="{Binding IsEditorChild,RelativeSource={RelativeSource AncestorType={x:Type UserControl}},Mode=OneWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource BoolToVisibilityConverter}}" />
                        </ContextMenu>
                    </ListBox.ContextMenu>
                </ListBox>
            </Grid>
        </GroupBox>
        <Grid Grid.Row="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <l49ui:ImageButton Grid.Column="0" MinWidth="70" Command="ApplicationCommands.Help" Image="pack://application:,,,/Resources/Images/question_16.png" ImageLocation="Left" Text="{lex:LocText LockCrypt.Core:Strings:Help}" ToolTip="{lex:LocText LockCrypt.Core:Strings:HelpContents}" Margin="0,2,2,2" />
            <Button Grid.Column="2" MinWidth="70" IsDefault="True" Command="ApplicationCommands.New" Content="{lex:LocText LockCrypt.Core:Strings:Generate}"/>
            <Button Grid.Column="3" MinWidth="70" Command="EditingCommands.Delete" Content="{lex:LocText LockCrypt.Core:Strings:Clear}"/>
            <Button Grid.Column="4" MinWidth="70" Command="ApplicationCommands.Save" Content="{lex:LocText LockCrypt.Core:Strings:Save}" />
            <Button Grid.Column="5" MinWidth="70" Command="ApplicationCommands.Open" Content="{lex:LocText LockCrypt.Core:Strings:SelectPassword}" Visibility="{Binding IsEditorChild,ElementName=root,Mode=OneWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource BoolToVisibilityConverter}}" />
        </Grid>
    </Grid>
</Window>
